<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Login</title>
    <!-- 使用CDN引入Bootstrap CSS -->
    <link href="/css/bootstrap.min.css" rel="stylesheet">    <!-- 添加样式调试标记 -->
    <style>
        body { background-color: #f8f9fa !important; }
        .container { border: 1px solid #dee2e6; padding: 2rem; }
    </style>
</head>
<body>
<div class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <h2 class="text-center mb-4">Login</h2>
            <form id="loginForm">
                <div class="mb-3">
                    <label for="username" class="form-label">Username</label>
                    <input type="text" class="form-control" id="username" name="username" required>
                </div>
                <div class="mb-3">
                    <label for="password" class="form-label">Password</label>
                    <input type="password" class="form-control" id="password" name="password" required>
                </div>
                <button type="submit" class="btn btn-primary w-100">Login</button>
            </form>
        </div>
    </div>
</div>
<!-- 使用CDN引入jQuery和Bootstrap JS -->
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.bundle.min.js"></script>
<script>
    $(document).ready(function () {
        $('#loginForm').on('submit', function (e) {
            e.preventDefault();

            const username = $('#username').val();
            const password = $('#password').val();

            const admin = {
                username: username,
                password: password
            };

            $.ajax({
                url: '/admins/adminLogin',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(admin),
                success: function (response) {
                    console.log('Login successful:', response);
                    // 添加页面跳转逻辑
                    window.location.href = '/adminMain'; // 根据实际路由配置调整路径
                },
                error: function (xhr, status, error) {
                    console.error('Login failed:', error);
                    alert('Login failed: ' + xhr.responseText);
                }
            });
        });
    });
</script>
</body>
</html>